package com.lechuang.songbo.view.activity.own;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;

import com.lechuang.songbo.model.LocalSession;
import com.lechuang.songbo.model.ShareModel;
import com.lechuang.songbo.presenter.net.QUrl;
import com.lechuang.songbo.utils.WebViewUtils;
import com.lechuang.songbo.view.defineView.ProgressWebView;
import com.lechuang.songbo.R;

/**
 * 作者：li on 2017/10/6 15:31
 * 邮箱：961567115@qq.com
 * 修改备注:
 */
public class ShareMoneyActivity extends AppCompatActivity implements View.OnClickListener {


    private ProgressWebView mWeb;
    private LocalSession session;
    private String url;
    private Context mContext = ShareMoneyActivity.this;
    private ImageView back;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share_money);
        initVeiw();
    }

    private void initVeiw() {
        session = LocalSession.get(this);
        //!=1 不是代理       =1 是代理
        if (session.getIsAgencyStatus() == 1) {
            url = QUrl.agentShare + "?i=" + session.getId();
        } else {
            url = QUrl.shareMoney;
        }
        mWeb = (ProgressWebView) findViewById(R.id.wv_money);
        back = (ImageView) findViewById(R.id.web_back);
        WebViewUtils.loadUrl(mWeb, this, url);
        //访问网络结束后，设置返回键显示。
        findViewById(R.id.iv_right).setVisibility(View.VISIBLE);
        findViewById(R.id.web_back).setVisibility(View.VISIBLE);
        findViewById(R.id.iv_right).setOnClickListener(this);
        back.setOnClickListener(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && mWeb.canGoBack()) {
            mWeb.goBack();// 返回前一个页面
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.web_back:
                finish();
                break;
            case R.id.iv_right:
                new ShareModel().gotoShareText(mContext, "玩转" + getResources().getString(R.string.app_name) + "分享赚钱:" + "\n" + url);
                //Utils.systemShare(mContext, "玩转" + getResources().getString(R.string.app_name) + "分享赚钱:" + "\n" + url);
                break;
        }
       /* NativeShareDialog shareDialog = new NativeShareDialog(this);
        shareDialog.setTitle("分享赚钱");
        //shareDialog.setBmUrl("");
        shareDialog.setDescription("玩转喜乐淘");
        shareDialog.setUrl(url);
        shareDialog.setPicUrl("");
        shareDialog.noSaveBitmap();
        shareDialog.show();*/


    }
}
